// miniprogram/pages/record/list.js
Page({
  data: {
    records: [],
    filterType: 'all', // all, income, expense
    currentDate: '',
    sceneType: ''
  },

  onLoad() {
    const app = getApp()
    this.setData({
      sceneType: app.globalData.sceneType
    })
    this.loadRecords()
  },

  onShow() {
    this.loadRecords()
  },

  loadRecords() {
    // 模拟数据
    const records = [
      { 
        id: 1, 
        ruleName: '完成家务', 
        points: 10, 
        description: '打扫客厅和厨房', 
        status: 'approved', 
        createdAt: '2023-05-15 18:30' 
      },
      { 
        id: 2, 
        ruleName: '运动健身', 
        points: 15, 
        description: '跑步30分钟', 
        status: 'pending', 
        createdAt: '2023-05-15 19:00' 
      },
      { 
        id: 3, 
        ruleName: '迟到', 
        points: -5, 
        description: '今天上班迟到了10分钟', 
        status: 'rejected', 
        createdAt: '2023-05-14 09:10' 
      },
      { 
        id: 4, 
        ruleName: '早睡早起', 
        points: 5, 
        description: '昨晚10点睡觉，今早6点起床', 
        status: 'approved', 
        createdAt: '2023-05-14 07:00' 
      }
    ]
    
    this.setData({ records })
  },

  filterRecords(e) {
    const type = e.currentTarget.dataset.type
    this.setData({ filterType: type })
    // 实际开发中这里会根据类型过滤数据
  },

  addRecord() {
    wx.navigateTo({
      url: '/pages/record/add'
    })
  },

  viewRecord(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/record/detail?id=${id}`
    })
  }
})